<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class DevicesResource extends ResourceCollection
{
    /**
     * 返回状态
     * @var bool
     */
    public $status;

    /**
     * 消息提示
     * @var string
     */
    public $message;

    /**
     * DevicesResource constructor.
     * @param mixed $resource
     * @param bool $status
     * @param string $message
     */
    public function __construct($resource, $status = true, $message = 'ok')
    {
        parent::__construct($resource);

        $this->status = $status;
        $this->message = $message;
    }

    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'data' => $this->collection,
            'status' => $this->status,
            'message' => $this->message
        ];
    }
}
